package com.learning.controller.admin;


import cn.hutool.core.bean.BeanUtil;
import com.learning.dto.PermissionDTO;
import com.learning.entity.Permission;
import com.learning.result.Result;
import com.learning.service.IPermissionService;
import com.learning.vo.PermissionVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 教师权限表 前端控制器
 * </p>
 *
 * @author itRao
 * @since 2024-05-23
 */
@RestController
@RequestMapping("/admin/permission")
@Slf4j
@RequiredArgsConstructor
@Api(tags = "权限相关接口")
public class PermissionController {

    private final IPermissionService permissionService;

    /**
     * 根据教师ID查询教师权限
     *
     * @param teacherId
     * @return
     */
    @ApiOperation("根据教师ID查询教师权限")
    @GetMapping("/{id}")
    public Result<PermissionVO> queryByTeacherId(@PathVariable("id") Long teacherId) {
        return permissionService.queryByTeacherId(teacherId);
    }

    /**
     * 修改教师权限
     *
     * @param permissionDTO
     * @return
     */
    @ApiOperation("修改教师权限")
    @PostMapping
    public Result<String> updatePermission(@RequestBody PermissionDTO permissionDTO) {

        permissionService.updatePermission(permissionDTO);

        return Result.success();
    }
}
